﻿using INTEX.DataBase;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Data;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class YCAABAUDIT : DocumentBase
    {
        #region-------------Properties-----------------------
        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        } 
 
        public YCAABAUDITData m_Data; 
        bool IsWLoaded = false;
        public string PrnType = "EXCEL";
        public SETINTEXDB SetData
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetData");
            }
        }
        public SETINTEXDB Set4ITX
        {
            get
            {
                return (SETINTEXDB)TryFindResource("Set4ITX");
            }
        }


        #region=====vwABPOS=======
        CollectionViewSource vwABPOS
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwABPOS");
            }
        }
        DataRow dwEKPOS
        {
            get
            {
                if (vwABPOS.View == null)
                    return null;
                if ((DataRowView)vwABPOS.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwABPOS.View.CurrentItem).Row;
            }
        }
        #endregion 
        public string KRS
        {
            get
            {
                return m_Data.Right("  " + txtAUFKRS.Text.ToString().Trim(), 2);
            }
            set
            {
                txtAUFKRS.Text = value;
            }
        }
        public string LFD
        {
            get
            {
                return m_Data.Right("000000" + txtAUFLFD.Text.ToString().Trim(), 6); ;
            }
            set
            {
                txtAUFLFD.Text = value;
            }
        }
        public string POS
        {
            get
            {
                return m_Data.Right("000000" + txtAUFPOS.Text.ToString().Trim(), 3); ;
            }
            set
            {
                txtAUFPOS.Text = value;
            }
        } 
        #endregion
        public YCAABAUDIT()
        {
            InitializeComponent();
            this.Name = "生产单管理";
        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            dicParamater["blBuildCellMastrix"] = false;
            base.SetUp(dicParamater);
            InitializeComponent();
           
            m_Data = new YCAABAUDITData();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {

                if (!IsWLoaded)
                {
                    IsWLoaded = true;
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return;

        }

        void vwABPOS_CurrentChanged(object sender, EventArgs e)
        {
          
        }

        public void btnQuery_Click(object sender, EventArgs e)
        {
            DataSet Result = new DataSet();
            DataRow dwInput;

            try
            {

                if (LFD.Trim() == "0000000")
                    return;
                dwInput = SetData.ABPOS.NewRow();
                dwInput["ABPMANDANT"] = "00";
                dwInput["ABPAUFKRS"] = KRS;
                dwInput["ABPAUFLFD"] = LFD;

                Result = m_Data.BuildData(dwInput);
                Set4ITX.Clear();
                Set4ITX.Merge(Result);
                if (vwABPOS.View != null)
                {
                    vwABPOS.View.MoveCurrentToFirst();
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void btnQuery2_Click(object sender, EventArgs e)
        {
            DataSet Result = new DataSet();
            DataRow dwInput;

            try
            { 
                Result = m_Data.INTEXDBC.QueryABPOS(null, 21);
                Result.Tables[0].TableName = "WDECK";
                Set4ITX.Clear();
                Set4ITX.Merge(Result);
           
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void btnQuery3_Click(object sender, EventArgs e)
        {
            DataSet Result = new DataSet();
            DataRow dwInput;

            try
            {
                Result = m_Data.INTEXDBC.QueryABPOS(null, 22);
                Result.Tables[0].TableName = "FDECK";
                Set4ITX.Clear();
                Set4ITX.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }


        private void cmdDeleteAB_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtDelete.Text.ToString().Trim() == "N")
                {
                    MessageBox.Show("如果你确认删除，请将标志改为Y");
                    return;
                }
                listGS08N.Text = "";
                string client = "00";             
                INTEXBL.DELTEABPOS(client, KRS, LFD);
                txtDelete.Text = "N";
                listGS08N.Text = KRS + LFD + "已经成功删除！";
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

    }
}
